<template>
    <div class="organization-main">
        <div class="organization-top">
            <el-input
                v-model="searchText"
                class="organization-search"
                placeholder="搜索"
                :prefix-icon="Search"
            />
            <el-icon class="organization-add"><Plus /></el-icon>
        </div>

        <el-scrollbar class="organization-list-scrollbar">
            <ul class="organization-list">  
                <li v-for="item in items" :key="item.name" :class="activeId === item.id ? 'organization-list-item-active' : ''"
                        @click="handleClickItem(item.id)">
                    <div class="organization-list-item">
                        <img :src="item.icon" alt="" class="organization-list-icon">
                        <div class="organization-item-right">
                            <h5>{{item.text}}</h5>
                            <el-icon><ArrowRight /></el-icon>
                        </div>
                    </div>
                </li>  
            </ul>
        </el-scrollbar>
    </div>
</template>

<script>
import {
    reactive,
    toRefs,
    onBeforeMount
} from "vue";
import { Search } from '@element-plus/icons-vue'

export default {
    name: "OrganizationList",

    setup() {
        const state = reactive({
            searchText: '',
            items: [
                {id: 0, text: '群聊', icon: require('@/assets/img (2).png')},
                {id: 1, text: '新的联系人', icon: require('@/assets/img (3).png')},
                {id: 2, text: 'xx科技', icon: require('@/assets/img (4).png')}
            ],
            activeId: 5
        });

        onBeforeMount(() => {
        });

        function handleClickItem(id) {
            state.activeId = id;
        }

        return {
            ...toRefs(state),
            Search,
            handleClickItem
        };
    },
};
</script>

<style lang="scss" scoped>
.organization-main {
    -webkit-app-region: no-drag;
    display: flex;
    flex-direction: column;
    
    .organization-top {
        display: flex;
        justify-content: center; 
        margin-top: 20px;
        margin-bottom: 10px;
        .organization-search {
            width: 166px;
            margin-right: 10px;
        }

        .organization-add {
            background: #e4e5e6;
            font-weight: 200;
            width: 32px;
            border-radius: 5px;
        }

        .organization-search, .organization-add {
            height: 32px;
        }

        :deep(.el-input__wrapper)  {
            background-color: #e5e5e7;
        }
    }

    .organization-list-scrollbar {
        flex: 1;

        .organization-list {
            margin-block-start: 0;
            margin-block-end: 0;
            padding-inline-start: 0;

            li {  
                list-style-type: none;

                &:hover {
                    background: #e4e4e6;
                }

                .organization-list-item {
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    border-bottom: 1px solid #dee0e2;
                    margin: 0 10px;
                    .organization-list-icon {
                        height: 20px;
                        width: 20px;
                        border-radius: 5px;

                        margin-left: 10px;
                        margin-top: 12px;
                        margin-bottom: 12px;
                    }

                    .organization-item-right {
                        width: 100%;
                        margin-left: 10px;
                        display: flex;
   
                        align-items: center;

                        h5 {
                            margin-block: 0;
                            font-weight: 500;
                            font-size: 14px;
                        }

                        .el-icon {
                            margin-left: auto;
                        }
                    }
                }

            }

            .organization-list-item-active {
                background: #d1dff1;
            }
        }
    }

}
</style>

